package 剑指Offer.easy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 翻转单词顺序 {
    static class Solution {
        public String reverseWords(String s) {
            String[] strings = s.trim().split(" ");
            StringBuilder res = new StringBuilder();
            for (int i = strings.length - 1; i >= 0; i--) {
                if (strings[i].equals(" ")) continue;
                res.append(strings[i]).append(" ");
            }
            return res.deleteCharAt(res.length() - 1).toString();
        }

        public static void main(String[] args) {
            Solution su = new Solution();
            String s = su.reverseWords("a good   example");
            System.out.println(s);
        }
    }
}
